(function() {
  app.run(function(toast_config, iphonex_footer, toast, $window, $rootScope, $location, $state, $interval, tradeApi, local_m, header_m, global_m, my_zxg_v) {
    tradeApi.sessionId = sessionStorage.getItem('session');
    toast_config.toggle = toast.ifVip('', 'get');
    my_zxg_v.updata(tradeApi.sessionId ? 'http' : 'local'); // 我的自选。本地，服务器存储选择
    $rootScope.iphonex_footer = iphonex_footer;

    $rootScope.$on('$stateChangeSuccess',
      function(event, toState, toParams, fromState, fromParams) {
        global_m
          .state_change(toState, fromState);
      }
    );

    $rootScope.$on('$stateChangeStart',
      function(event, toState, toParams, fromState, fromParams) {
        angular.element(document).ready(function(){
          angular.element(document).scrollTop(0)
        })
        if (!toState.notNeedLogin) {
          if (tradeApi.sessionId === null || tradeApi.sessionId === '') {
            event.preventDefault();
            $state.go('login', { go_to: toState.name, go_to_params: toParams });
          }
        }
        $rootScope.current_state = toState.url;
      }
    );

    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == 'iphone os';
    var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
    var bIsUc = sUserAgent.match(/ucweb/i) == 'ucweb';
    var bIsAndroid = sUserAgent.match(/android/i) == 'android';
    var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
    var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
      sessionStorage.removeItem('devicetype');
    } else {
      if (sessionStorage.getItem('devicetype')) {

      } else {
        sessionStorage.setItem('devicetype', 'pc');
        location.href = "./free-index-pc.html"
      }
    }
  });
})();